package com.rabbit.topic;

import java.io.IOException;

import com.rabbit.RabbitFactory;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author CUIJIAJUN
 * @date   2017年2月15日
 * 
 */
public class SendLogTopic {
    private static final String EXCHANGE_NAME = "topic_logs";  

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {

		Connection connection = RabbitFactory.creatConnection();
		Channel channel = connection.createChannel();
		
		channel.exchangeDeclare(EXCHANGE_NAME, "topic");
        //定义绑定键     
		String[] routing_keys = new String[]{"kernal.info", "cron.warning",    
                "auth.info", "kernel.critical" };

        for (String routing_key : routing_keys)    
        {     
            //发送4条不同绑定键的消息  
            String msg = "我是小西_"+routing_key;    
            channel.basicPublish(EXCHANGE_NAME, routing_key, null, msg    
                    .getBytes());    
            System.out.println(" [x] Sent routingKey = "+routing_key+" ,msg = " + msg + ".");    
        }    
    
        channel.close();    
        connection.close();    
	}

}
